---@class Battle.AiBlackboard
local AiBlackboard = Battle.CreateClass("AiBlackboard")
Battle.AiBlackboard = AiBlackboard
function AiBlackboard:ctor()
    self.triggerList = {}
    self.observerList = {}
end
function AiBlackboard:Set(name,value)
    if self.triggerList[name] ~= value then
        local list = self.observerList[name]
        if list then
            for k,v in pairs(list) do
                v.callback(v.tb,name,self.triggerList[name],value)
            end
        end
    end
    self.triggerList[name] = value
end
function AiBlackboard:Get(name)
    return self.triggerList[name]
end
function AiBlackboard:AddObserver(name,callback,tb)
    local list = self.observerList[name]
    if not list then
        list = {}
        self.observerList[name] = list
    end
    for k,v in pairs(list) do
        if v.callback == callback and v.tb == tb then
            return
        end
    end
    table.insert(list,{callback = callback,tb = tb})
end
function AiBlackboard:RemoveObserver(name,callback,tb)
    local list = self.observerList[name]
    if not list then return end
    for k,v in pairs(list) do
        if v.callback == callback and v.tb == tb then
            table.remove(list,k)
            return
        end
    end
end